package com.ccc.oa.user.controller;

import com.ccc.oa.common.core.common.R;
import com.ccc.oa.common.core.excepiton.CommonExcepiton;
import com.ccc.oa.user.param.LoginParam;
import com.ccc.oa.user.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * --- 代码敲对！ ---
 *
 * @author CCCccc
 * @create 2025/10/10
 * 备注：登录功能控制层
 */
// 该注解表示启用验证框架
@Validated
// 该注解表示该类所有的接口允许跨域
@CrossOrigin("*")
// 该注解表示该类为控制层
@RestController
// 该注解表示该类中所有接口的请求路径前缀为/api/user
@RequestMapping("/api/user")
public class LoginController {

    @Resource
    private UserService userService;

    /**
     * 登录接口
     */
    @RequestMapping("/login")
    // @Valid该注解表示开启LiongParam中的验证
    public R login(@Valid @RequestBody LoginParam loginParam){
        try {
            String token = userService.login(loginParam);
            return R.success(token);
        }catch (CommonExcepiton e){
            throw e;
        }
    }
}
